package com.common.excel.controller;

import com.common.excel.entity.TestBean;
import com.hqd.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/uploadExcel")
@Api(tags = "EXCEL公共导入")
public class UploadExcelController {


    @ApiOperation(value = "导入",notes = "导入")
    @PostMapping(value = "/upload")
    public <T> ResultBody upload(MultipartFile file, Class<T> tClass,String productSource){
        try {
            //ExcelUtils.readExcel(tClass, file, productSource);
            return ResultBody.ok();
        }catch (Exception e){
            return ResultBody.failed().msg(e.getMessage());
        }
    }

    @ApiOperation(value = "导入测试",notes = "导入测试")
    @PostMapping(value = "/test")
    public ResultBody<String> test(MultipartFile file ,String productSource){
        return upload(file,TestBean.class,productSource);
    }

}
